package com.wenzhi.studentservice.controller;

import com.wenzhi.studentservice.dto.StudentAddDTO;
import com.wenzhi.studentservice.dto.StudentListDTO;
import com.wenzhi.studentservice.dto.StudentUpdateDTO;
import com.wenzhi.studentservice.service.IStudentService;
import com.wenzhi.studentservice.vo.ResultVO;
import com.wenzhi.studentservice.vo.StudentListVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource
    private IStudentService studentService;

//    @GetMapping("/list")
//    public ResultVO<Boolean> list(StudentListDTO dto) {
//
//        return null;
//    }

    @GetMapping("/list")
    public ResultVO<List<StudentListVO>> list(StudentListDTO dto) {
        // shift+alt+enter
        List<StudentListVO> list = studentService.list(dto);
        return ResultVO.success(list);
    }

//    @GetMapping("/list")
//    public ResultVO<List<Boolean>> list(StudentListDTO dto) {
//
//        return null;
//    }

    @PostMapping("/add")
    public ResultVO<Long> add(@RequestBody StudentAddDTO dto) {
        // alt + enter
        Long id = studentService.add(dto);
        return ResultVO.success(id);
    }

    @PutMapping("/update")
    public ResultVO<Boolean> update(@RequestBody StudentUpdateDTO dto) {
        boolean result = studentService.update(dto);
        return ResultVO.success(result);
    }

}
